import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 * @file MainScreen.java
 * @author chenyu
 * @mail 514813857@qq.com
 * @data 2014年4月22日 下午11:15:43
 * @description: 主界面绘制
 */
public class MainScreen extends Canvas {
	
	private Display display;
	private DisplayCanvas midlet;
	private FileBrowser fileList;
	private Image imgLogo;
	public MainScreen(Display display,DisplayCanvas midlet){
		this.setFullScreenMode(true);
		this.display = display;
		this.midlet = midlet;
		
		try {
			imgLogo = Image.createImage("/logo-white.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		fileList = new FileBrowser();
	}
	protected void paint(Graphics g) {
		// TODO Auto-generated method stub
		g.drawImage(imgLogo,0,0,0);
		g.setColor(255, 0, 0);
		g.setColor(0, 0, 0);
		g.drawString("看书", getWidth()/2, getHeight(), 33);
		g.drawString("退出", getWidth(), getHeight(), 40);
	}
	
	protected void keyPressed(int keyCode){
		int action = this.getGameAction(keyCode);
		
		switch(action){
		case Canvas.FIRE:
			display.setCurrent(fileList);
			break;
		case 0:
			if(keyCode == -7){
				
				midlet.notifyDestroyed();
				
			}
			break;
			default:
				break;
		}
	}
}
